package com.ruibang.glass.purchase.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruibang.glass.common.domain.camunda.BpmProcessInstanceCreate;
import com.ruibang.glass.purchase.domain.req.PurchaseApprovalReq;
import com.ruibang.glass.purchase.domain.req.PurchaseDullnessReq;
import com.ruibang.glass.purchase.entity.PurchaseApprovalList;
import com.ruibang.glass.purchase.service.PurchaseApprovalItemsService;
import com.ruibang.glass.purchase.service.PurchaseApprovalListService;
import com.ruibang.glass.purchase.service.PurchaseApprovalSupplierService;
import com.teaming.cloud.framework2.common.constant.CommonConstant;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author mameng
 * 采购审批
 */
@Api(tags = "采购审批")
@RestController
@RequestMapping("/api/glass/purchase/approve")
public class PurchaseApproveListController {


    @Autowired
    private PurchaseApprovalListService purchaseApprovalListService;

    @Autowired
    private PurchaseApprovalItemsService purchaseApprovalItemsService;

    @Autowired
    private PurchaseApprovalSupplierService purchaseApprovalSupplierService;

    @PostMapping("/list")
    @ApiOperation(value = "采购审批列表", response = ResultBody.class)
    public ResultBody queryPage(@RequestBody PurchaseApprovalReq purchaseReportReq) {
        return ResultBody.success(purchaseApprovalListService.queryPage(purchaseReportReq));
    }

    @GetMapping("/getInfoByNumber")
    @ApiOperation(value = "根据项目编号查询审批信息", response = ResultBody.class)
    public ResultBody getByNumber(@RequestParam("number") String number) {
        return ResultBody.success(purchaseApprovalListService.getInfoByNumber(number));
    }

    @PostMapping("/updatePurchaseApprovalList")
    @ApiOperation(value = "采购审批跟新", response = ResultBody.class)
    public ResultBody updatePurchaseApprovalList(@RequestBody PurchaseApprovalList purchaseApprovalList) {
        purchaseApprovalListService.updatePurchaseApprovalList(purchaseApprovalList);
        return ResultBody.success();
    }

    @GetMapping("/processNotice/{businessId}")
    @ApiOperation(value = "流程处理通知", response = ResultBody.class)
    public ResultBody processNotice(@PathVariable("businessId") String businessId) {
        purchaseApprovalListService.processNotice(businessId);
        return ResultBody.success();
    }

    @PostMapping("/approveProject")
    @ApiOperation(value = "发起立项审批", response = ResultBody.class)
    public ResultBody approveProject(@RequestBody BpmProcessInstanceCreate BpmProcessInstanceCreate) {
        purchaseApprovalListService.approveProject(BpmProcessInstanceCreate);
        return ResultBody.success();
    }

    @GetMapping("/deleteSupplier/{id}")
    @ApiOperation(value = "删除供应商", response = ResultBody.class)
    public ResultBody deleteSupplier(@PathVariable("id") String id) {
        return ResultBody.success(purchaseApprovalSupplierService.removeById(id));
    }

    @GetMapping("/deleteItem/{id}")
    @ApiOperation(value = "删除商品", response = ResultBody.class)
    public ResultBody deleteItem(@PathVariable("id") String id) {
        return ResultBody.success(purchaseApprovalItemsService.removeById(id));
    }

    @PostMapping("/addPurchaseApprovalList")
    @ApiOperation(value = "采购审批新增", response = ResultBody.class)
    public ResultBody queryAreas(@RequestBody PurchaseApprovalList purchaseApprovalList) {
        purchaseApprovalListService.addPurchaseApprovalList(purchaseApprovalList);
        return ResultBody.success();
    }

    @GetMapping("/getProjectNameList")
    @ApiOperation(value = "采购项目编号下拉", response = ResultBody.class)
    public ResultBody getProjectNameList() {
        return ResultBody.success(purchaseApprovalListService.getProjectNameList());
    }

    /*@GetMapping("/getContractsProject")
    @ApiOperation(value = "合同项目下拉接口", response = ResultBody.class)
    public ResultBody getContractsProject() {
        return ResultBody.success(purchaseApprovalListService.getContractsProject());
    }

    @GetMapping("/getFrameContractsProject")
    @ApiOperation(value = "获取框架合同项目下拉接口", response = ResultBody.class)
    public ResultBody getFrameContractsProject() {
        return ResultBody.success(purchaseApprovalListService.getFrameContractsProject());
    }*/

    @GetMapping("/getReportProject")
    @ApiOperation(value = "评标报告项目下拉接口", response = ResultBody.class)
    public ResultBody getReportProject() {
        return ResultBody.success(purchaseApprovalListService.getReportProject());
    }

    @GetMapping("/getOne/{id}")
    @ApiOperation(value = "获取详情", response = ResultBody.class)
    public ResultBody getOne(@PathVariable("id") String id) {
        return ResultBody.success(purchaseApprovalListService.getPurchaseApprovalList(id));
    }

    @GetMapping("/getById/{id}")
    @ApiOperation(value = "详情", response = ResultBody.class)
    public ResultBody getById(@PathVariable("id") String id) {
        return ResultBody.success(purchaseApprovalListService.getPurchaseApprovalList(id));
    }

    @PostMapping("/updatePurchaseApprovalBYDelete")
    @ApiOperation(value = "发起废止", response = ResultBody.class)
    public ResultBody updatePurchaseApprovalBYDelete(@RequestBody PurchaseApprovalList purchaseApprovalList) {
        purchaseApprovalListService.updatePurchaseApprovalBYDelete(purchaseApprovalList);
        return ResultBody.success();
    }

    @PostMapping("/addPurchaseDetail")
    @ApiOperation(value = "生成采购订单", response = ResultBody.class)
    public ResultBody addPurchaseDetail(@RequestBody PurchaseApprovalList purchaseApprovalList) {
        purchaseApprovalListService.addPurchaseDetail(purchaseApprovalList);
        return ResultBody.success();
    }


    @GetMapping("/getKjxContractList")
    @ApiOperation(value = "框架性合同下拉", response = ResultBody.class)
    public ResultBody getKjxContractList() {
        return ResultBody.success(
                purchaseApprovalListService.list(Wrappers.<PurchaseApprovalList>lambdaQuery()
                        .select(PurchaseApprovalList::getId, PurchaseApprovalList::getProjectName, PurchaseApprovalList::getNumber).eq(PurchaseApprovalList::getSpStatus,CommonConstant.THREE_STR)
                ));
    }

    @GetMapping("/getApproveSequenceNumber")
    @ApiOperation(value = "获取申请编号", response = ResultBody.class)
    public ResultBody getApproveSequenceNumber() {
        return ResultBody.success(purchaseApprovalListService.getApproveSequenceNumber());
    }

    @PostMapping("/dullnessList")
    @ApiOperation(value = "采购呆滞统计", response = ResultBody.class)
    public ResultBody dullnessList(@RequestBody PurchaseDullnessReq purchaseApprovalList) {
        return ResultBody.success( purchaseApprovalListService.dullnessList(purchaseApprovalList));
    }

}
